<template>
	<v-forms ref="formRef" :label-width="120"> </v-forms>
</template>
<script lang="ts">
import { defineComponent, ref, onMounted, reactive, toRefs, computed } from 'vue';
import VForms from '/@/components/forms/v-forms.vue';
import { validateNumber } from '/@/utils/validators';
import { ElMessage, ElMessageBox } from 'element-plus';
import request from '/@/api/develop/dic';
export default defineComponent({
	components: {
		VForms,
	},
	setup() {
		const formRef = ref();

		const state = reactive({});

		const addNew = async (data: any = {}) => {

            /**
             * 
             *  {
                    请输入公司名称: name, 
                    请输入管理员姓名:  管理员姓名  adminName
                    邮箱(账号)  请输入电子邮箱 email
                    电话号码 请输入电话号码 phone
                    请输入备注 remark
                }
             */
			let formList: any[] = [
				{
					type: 'input',
					key: 'name',
					label: '公司名称',
					value: data.name || '',
					placeHolder: '请输入公司名称',
					rules: [{ required: true, message: '公司名称不能为空', trigger: ['blur', 'change'] }],
				},
				{
					type: 'input',
					key: 'adminName',
					label: '管理员姓名',
					placeHolder: '请输入管理员姓名',
					value: data.adminName || '',
					rules: [{ required: true, message: '管理员姓名不能为空', trigger: ['blur', 'change'] }],
				},{
					type: 'input',
					key: 'email',
					label: '邮箱(账号)',
					placeHolder: '请输入电子邮箱',
					value: data.email || '',
					rules: [{ required: true, message: '邮箱不能为空', trigger: ['blur', 'change'] }],
				},{
					type: 'input',
					key: 'phone',
					label: '电话号码',
					placeHolder: '请输入电话号码',
					value: data.phone || '',
					rules: [{ required: false, message: '电话号码不能为空', trigger: ['blur', 'change'] }],
				},
				{
					type: 'textarea',
					key: 'remark',
					label: '备注',
					placeHolder: '请输入备注',
					value: data.remark || '',
					rules: [{ required: false, message: '备注不能为空', trigger: ['blur', 'change'] }],
				},
			];

			if (data.id) {
				formList.push({
					type: 'input',
					label: 'id',
					key: 'id',
					show: false,
					value: data.id,
					rules: [{ required: false, message: `id不能为空`, trigger: 'change' }],
				});
			}

			let title = data.id ? '编辑租户' : '新增租户';

			formRef.value.openDialog(formList, title);
		};
		return {
			formRef,
			addNew,
			...toRefs(state),
		};
	},
});
</script>

<style lang="scss" scoped>
.select-list {
	:deep(.el-form-item) {
		margin: 15px 0;
	}
}
</style>
